/**
 * HTTPTransport
 *
 * Implement a http transport
 *
 * At the moment, this is just a quick and ugly hack to get
 * something up an running.
 *
 */

package uk.co.sheitgeist.fums.server.content.transport.http

import uk.co.sheitgeist.fums.server.content.transport.*
import uk.co.sheitgeist.fums.server.content.store.*

import org.mortbay.jetty.Server
import org.mortbay.jetty.Handler
import org.mortbay.jetty.handler.HandlerCollection
import org.mortbay.jetty.handler.HandlerList;
import org.mortbay.jetty.handler.DefaultHandler;

public class HTTPTransport implements Transport {

	Server server = new Server(8888)
//	def innerHandlers = [new DefaultHandler()]
	Handler handler
	public HTTPTranport() {
//         server.setHandler(handlers)
	}
	public addHandler(Handler handler) {
//		innerHandlers.add(0,handler)
		this.handler = handler
	}

	public String getUrl(StoreNode node) {
		return "http://192.168.1.4:8888/${this.handler.getStorePath(node.id)}" 

	}

	public void start() {
		HandlerList handlers = new HandlerList();
	//	handlers.setHandlers([this.handler,new DefaultHandler()])
		server.setHandler(this.handler);
		
		server.start()
		server.join()
	}

	public void stop() {
		server.stop()
	}

}
